package com.hangzhou.xyj.ui.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import com.hangzhou.xyj.R;
import com.hangzhou.xyj.manager.IntentManager;
import com.hangzhou.xyj.model.DramaModel;
import com.hangzhou.xyj.model.DynamicModel;
import com.hangzhou.xyj.ui.adapter.base.BaseLoadingAdapter;
import com.hangzhou.xyj.ui.adapter.viewholder.DynamicListenViewHolder;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by DT-038 on 2015/12/28.
 * 曲目动态adapter
 */
public class DramaDynamicsAdapter extends BaseLoadingAdapter<DynamicModel> {


    public DramaDynamicsAdapter(RecyclerView recyclerView, List<DynamicModel> dataList) {
        super(recyclerView, dataList);
    }

    @Override
    public RecyclerView.ViewHolder onCreateNormalViewHolder(ViewGroup viewGroup, int viewType) {
        RecyclerView.ViewHolder viewHolder;
        switch (viewType) {
            default:
                viewHolder = new DynamicListenViewHolder(mContext, mLayoutInflater.inflate(R.layout.layout_active_item_listen, viewGroup, false));
                break;
        }
        return viewHolder;
    }


    @Override
    public void onBindNormalViewHolder(RecyclerView.ViewHolder viewHolder, final int position) {
        if (viewHolder == null) {
            return;
        }
        if (viewHolder instanceof DynamicListenViewHolder) {

            ((DynamicListenViewHolder) viewHolder).setData(mDataList.get(position));
            viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
//                    DynamicModel dynamicModel = mDataList.get(position);
                    List<DramaModel> modelList = new ArrayList<>();
                    for (DynamicModel model : mDataList) {
                        if (model == null) {
                            continue;
                        }
                        DramaModel dramaModel = new DramaModel();
                        dramaModel.setId(model.getId());
                        dramaModel.setName(model.getSongName());
                        dramaModel.setNativeUrl(model.getNativeUrl());
                        dramaModel.setAccompanyUrl(model.getAccompanyUrl());
                        dramaModel.setLrcUrl(model.getLrcUrl());
                        modelList.add(dramaModel);
                    }
                    IntentManager.getInstance().goDramaPlayActivity(mContext, modelList, position);
                }
            });
        }
    }

}
